<template>
  <div class="AddOrUpdate_main add_container showDetail column_three" :class="showKey.type">
    <div class="main_main">
      <el-form ref="form" :model="formData" :rules="rules" :inline="true">
        <div
          v-for="(item2,index2) in showKey.keys"
          :key="'index2'+index2"
          :class="getClass(item2)"
        >
          <el-form-item v-if="item2.type==='br'" class="showItem_br" />
          <el-form-item v-if="item2.type==='form' " :label="item2.name" :show-overflow-tooltip="true">
            <div v-if="!showData[item2.key]&&showData[item2.key]!=='0'" class="show noData">暂无</div>
            <div v-else-if="item2.key==='status'" class="show">{{ showData[item2.key]==='1'||showData[item2.key]===1?'启用':'停用' }}</div>
            <div v-else class="show gridBoxContentSelf">{{ showData[item2.key] }}</div>
          </el-form-item>
          <el-form-item v-if="item2.type==='Invoices'" :label="item2.name" :show-overflow-tooltip="true">
            <div class="show gridBoxContentSelf">{{ showData[item2.key] }}</div>
          </el-form-item>
          <el-form-item v-if="item2.type==='file'" :label="item2.name">
            <FileManageFull
              :file-names="showData[item2.fileName]"
              :file-real-names="showData[item2.fileRealName]"
              :file-urls="showData[item2.fileUrl]"
              :row-index="1"
              :readonly="true"
              @fileName="setFileName"
            />
          </el-form-item>

          <div v-if="item2.type==='table'" class="formItem_header">
            {{ item2.name }}
          </div>
          <div v-if="item2.type==='table'" ref="table_container" class="table_container">
            <el-table
              ref="table"
              :data="showData[item2.key]"
              :height="tableHeight"
              stripe
              border
              row-key="id"
            >
              <el-table-column
                v-for="(item3,index3) in item2.columns"
                :key="index3"
                :label="item3.name"
                :prop="item3.key"
                :min-width="item3.minWidth||100"
                :show-overflow-tooltip="true"
                :fixed="item3.fixed"
              >
                <template slot-scope="scope">
                  <div
                    v-if="item3.type==='column'"
                    style=" white-space:nowrap; text-overflow:ellipsis; overflow:hidden;"
                  >{{ scope.row[item3.key] }}</div>
                  <FileManage
                    v-if="item3.type==='file'"
                    :file-names.sync="scope.row[item3.fileName]"
                    :file-real-names.sync="scope.row[item3.fileRealName]"
                    :file-urls.sync="scope.row[item3.fileUrl]"
                    :row-index="scope.$index"
                    :readonly="true"
                    @fileName="setFileName"
                  />
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="formItem_header">
          打印记录
        </div>
        <div ref="print_table_container" class="table_container">
          <el-table
            ref="print_table"
            :data="printTabledata"
            stripe
            border
            row-key="id"
            style="width: 99.9%;"
            border
            :show-header="false"
          >
            <el-table-column label="打印名称" width="140" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ scope.row.userRealName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="打印时间" :min-width="SETTINGS.settings_decimalDigits_length" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ scope.row.printTime }}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="print_pagination">
            <div class="print_total">合计: {{ total }}次</div>
            <div>
              <el-pagination
                background
                :selected-num="selectionsAll.length"
                :page-size="5"
                layout="prev, pager, next"
                :total="total"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </div>
      </el-form>
    </div>
    <div class="main_bottom">
      <div><el-button @click.stop="printExcel">打印</el-button></div>
    </div>
  </div>
</template>

<script>
import { getPrintlist } from '@/api/saleManage/saleSend'
import { getReportUrl } from '@/api/superManage/reportForm'
import { addCreate, getSaleReturnStatus } from '@/api/saleManage/saleReturn'
export default {
  name: 'ShowDetailOld',
  props: {
    layerid: {},
    id: {},
    showKey: {},
    showData: {},
    businessId: {}
  },
  data() {
    return {
      formData: {},
      rules: {},
      pageData: {
        pageNum: 1,
        pageSize: 5,
        modelName: '销售退货单'
      },
      enterWarehouseInvoices: '',
      saleReturnStatus: '',
      tableHeight: '300',
      printTabledata: [],
      selectionsAll: [], // 表格所有页选中的行
      total: 0, // 打印合计次数
      pageId: '查看' // 页面唯一标识
    }
  },
  mounted() {
    this.getList()
    // this.getSaleReturnStatusInfo()
    if (this.showData.enterWarehouseInvoices == '1') {
      this.enterWarehouseInvoices = '1'
    }
  },
  methods: {// 表格拖动排序
    // getSaleReturnStatusInfo() { // 获取系统设置里销售退货单是否生成入库单的状态
    //   if (this.showData.status == '0' || this.showData.status == '3') {
    //     getSaleReturnStatus('saleReturnStatus').then(res => {
    //       this.saleReturnStatus = res.data.saleReturnStatus
    //     })
    //   } else {
    //     this.saleReturnStatus = '1'
    //   }
    // },
    create() { // 生成入库单
      addCreate({ ...this.showData, enterWarehouseInvoices: '1' }).then(res => {
        if (res.code == 200) {
          this.enterWarehouseInvoices = '1'
          this.$message.success('操作成功')
          this.$parent.getList()
        }
      })
    },
    printExcel() {
      getReportUrl({
        getInfoId: [this.showData.id],
        menuPath: this.$route.path
      }).then(res => {
        res.data.forEach(ele => {
          window.open(ele)
        })
      })
    },
    // 打印列表
    getList() {
      getPrintlist({ ...this.pageData, businessId: this.businessId }).then(res => {
        this.total = res.total
        this.printTabledata = res.data
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
        })
      })
    },
    // 分页切换
    handleCurrentChange(val) {
      this.pageData.pageNum = val
      this.getList()
    },
    cancel() {
      this.$layer.close(this.layerid)// 关闭弹框
    },
    setFileName(...data) {
      this.tableData[data[3]].fileName = data[0]
      this.tableData[data[3]].fileRealName = data[1]
      this.tableData[data[3]].fileUrl = data[2]
    },
    getClass(item) {
      let res = ''
      if (item.type === 'form' || item.type === 'br' || item.type === 'Invoices') {
        res += 'showItem'
        if (item.length && item.length === 'double') {
          res += ' double'
        }
      } else if (item.type === 'file') {
        res += 'showItem double'
      } else {
        res += 'showTable'
      }

      return res
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .el-button--medium {
  display: flex;
  align-items: center;
  justify-content: center;
}
.Invoices {
  width: calc(100% - 40px) !important;
}
.Invoices_button {
  line-height: 50px !important;
  display: flex;
  align-items: center;
  /deep/ .el-button--default {
    width: 71px !important;
    margin-left: 10px !important;
  }
}
.Invoices_text {
  line-height: 50px !important;
  padding-left: 10px;
}
.Invoices_button_text {
  display: block;
  width: 100% !important;
  color: #c0c4cc;
}
//.gridBoxContentSelf {
//  width: 290px !important;
//  overflow:hidden !important; //超出的文本隐藏
//  text-overflow:ellipsis !important; //溢出用省略号显示
//  white-space:nowrap !important; //溢出不换行
//}
.main_bottom{
  margin-bottom: -10px;
}
/deep/ .el-table--border {
  border-bottom: 1px solid #dfe6ec;
}
/deep/ .el-table__fixed-footer-wrapper {
  .el-table__cell:last-of-type {
    height: 39px !important;
  }
}
.print_pagination{
  margin: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .print_total{
    margin-left: 15px;
    color: #333;
    font-size: 15px;
  }
}
.main_main{

  .el-form{
    height: 100%;
    align-content: flex-start;

    .showItem{
      margin-left: 20px;
      margin-right: 20px;
      width: calc(33.33% - 40px);
    }

    /deep/ .el-form-item{
      width: 100%;
      border-bottom: 1px solid rgba(105,105,105,0.2);
      margin-left: 0;
      margin-right: 0;

      .el-form-item__label:before{
        content: none;
      }
      .el-form-item__label{
        color: #1F51B3;
        font-size: 15px;
      }
      .el-form-item__content{
        word-break: break-all;
        color: #333333;
        font-size: 15px;
        flex: 1;
        width: unset;
        margin-right: 0px;
      }
    }
    .double{
      width: calc(100% - 40px);
      //.show{
      //  overflow: hidden;
      //  text-overflow: ellipsis;
      //  display: -webkit-box;
      //  -webkit-line-clamp: 2;
      //  -webkit-box-orient: vertical;
      //}
    }
  }
  .showTable{
    width: 100%;
  }
}

.column_one{
  .showItem{
    width: 100% !important;
  }
}
.noData{
  color: #c0c4cc;
}
.show{
  height: fit-content !important;
  padding-top: 10px;
  padding-bottom: 10px;
}
.FileManageFull_container{
  padding-top: 10px;
  padding-left: 10px;
}
.showItem_br{
  border-bottom: 0 !important;
}
.formItem_header{
  font-size: 18px;
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding-left: 20px;
  padding-right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.table_container {
  padding-top: 0px !important;
}
.el-table {
  font-size: 15px;
}
</style>
